package org.example.library.service;

import org.example.library.dao.UserDao;
import org.example.library.vertile.User;

public class UserService {
    UserDao userDao = new UserDao();
    public int register(String username,String password){
        if(username==null||password==null){
            return 0;
        }
        if(username.trim().isEmpty()||password.trim().isEmpty()){
            return 0;
        }
        if(userDao.isExistUser(username)){
            return -1;
        }
        return userDao.addUser(username,password);
    }

    public int login(String username,String password){
        User user = new User();
        user = userDao.queryUser(username);
        if(username==null||password==null){
            return 0;
        }
        if(username.trim().isEmpty()||username.trim().isEmpty()){
            return 0;
        }
        if(!userDao.isExistUser(username)){
            return -1;
        }
        else if(password.equals(user.getPassword())){
            return 1;
        }
        return 0;

    }

}
